<html><head><title>Truncated Probability Density Function of a gamlss.family Distribution</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="Rchm.css">
</head>
<body>

<table width="100%"><tr><td>trun.d(gamlss.tr)</td><td align="right">R Documentation</td></tr></table><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
<param name="keyword" value="R:   trun.d">
<param name="keyword" value=" Truncated Probability Density Function of a gamlss.family Distribution">
</object>


<h2>Truncated Probability Density Function of a gamlss.family Distribution</h2>


<h3>Description</h3>

<p>
Creates a truncated probability density function version from a current GAMLSS family distribution
</p>


<h3>Usage</h3>

<pre>
trun.d(par, family = "NO", type = c("left", "right", "both"), ...)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>par</code></td>
<td>
a vector with one (for <code>left</code> or <code>right</code> truncation) or two elements for <code>both</code>   </td></tr>
<tr valign="top"><td><code>family</code></td>
<td>
a <code><a onclick="findlink('gamlss', 'gamlss.family.html')" style="text-decoration: underline; color: blue; cursor: hand">gamlss.family</a></code> object, which is used to define the distribution and the link functions of the various parameters. 
The distribution families supported by <code>gamlss()</code> can be found in <code><a onclick="findlink('gamlss', 'gamlss.family.html')" style="text-decoration: underline; color: blue; cursor: hand">gamlss.family</a></code>.
Functions such as BI() (binomial) produce a family object. </td></tr>
<tr valign="top"><td><code>type</code></td>
<td>
whether <code>left</code>, <code>right</code> or in <code>both</code> sides truncation is required, (left is the default).</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
for extra arguments </td></tr>
</table>

<h3>Details</h3>




<h3>Value</h3>

<p>
Returns a d family function</p>

<h3>Note</h3>




<h3>Author(s)</h3>

<p>
Mikis Stasinopoulos <a href="mailto:d.stasinopoulos@londonmet.ac.uk">d.stasinopoulos@londonmet.ac.uk</a> and Bob Rigby <a href="mailto:r.rigby@londonmet.ac.uk">r.rigby@londonmet.ac.uk</a>
</p>


<h3>References</h3>

<p>
Rigby, R. A. and  Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), 
<EM>Appl. Statist.</EM>, <B>54</B>, part 3, pp 507-554.
</p>
<p>
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2003) Instructions on how to use the GAMLSS package in R.
Accompanying documentation in the current GAMLSS  help files, (see also  <a href="http://www.gamlss.com/">http://www.gamlss.com/</a>).
</p>


<h3>See Also</h3>

<p>
<code><a href="trun.p.html">trun.p</a></code>, <code><a href="trun.q.html">trun.q</a></code>, <code><a href="trun.r.html">trun.r</a></code>, <code><a href="gen.trun.html">gen.trun</a></code>
</p>


<h3>Examples</h3>

<pre>
# continuous distribution 
# left truncation 
test1&lt;-trun.d(par=c(0), family="TF", type="left")
test1(1)
dTF(1)/(1-pTF(0))
if(abs(test1(1)-(dTF(1)/pTF(0)))&gt;0.00001) stop("error in left trucation")
test1(1, log=TRUE)
log(dTF(1)/(1-pTF(0)))
if(abs(test1(1, log=TRUE)-log(dTF(1)/pTF(0)))&gt;0.00001) stop("error in left trucation")
#if (!identical(test1(1, log=TRUE), log(dTF(1)/(1-pTF(0)))))   stop("error in left trucation")
 integrate(function(x) test1(x, mu=-2, sigma=1, nu=1),0,Inf) # the pdf is defined even with negative mu
 integrate(function(x) test1(x, mu=0, sigma=10, nu=1),0,Inf) 
 integrate(function(x) test1(x, mu=5, sigma=5, nu=10),0,Inf)
plot(function(x) test1(x, mu=-3, sigma=1, nu=1),0,10)
plot(function(x) test1(x, mu=3, sigma=5, nu=10),0,10)
#----------------------------------------------------------------------------------------
# right truncation
test2&lt;-trun.d(par=c(10), family="BCT", type="right")
test2(1)
dBCT(1)/(pBCT(10))
#if(abs(test2(1)-(dBCT(1)/pBCT(10)))&gt;0.00001) stop("error in right trucation")
test2(1, log=TRUE)
log(dBCT(1)/(pBCT(10)))
if(abs(test2(1, log=TRUE)-log(dBCT(1)/(pBCT(10))))&gt;0.00001) stop("error in right trucation")
integrate(function(x) test2(x, mu=2, sigma=1, nu=1),0,10) 
integrate(function(x) test2(x, mu=2, sigma=.1, nu=1),0,10) 
integrate(function(x) test2(x, mu=2, sigma=.1, nu=10),0,10) 
plot(function(x) test2(x, mu=2, sigma=.1, nu=1),0,10)
plot(function(x) test2(x, mu=2, sigma=1, nu=1),0,10)
#----------------------------------------------------------------------------------------
# both left and right truncation
test3&lt;-trun.d(par=c(-3,3), family="TF", type="both")
test3(0)
dTF(0)/(pTF(3)-pTF(-3))
if(abs(test3(0)-dTF(0)/(pTF(3)-pTF(-3)))&gt;0.00001) stop("error in right trucation")
test3(0, log=TRUE)
log(dTF(0)/(pTF(3)-pTF(-3)))
if(abs(test3(0, log=TRUE)-log(dTF(0)/(pTF(3)-pTF(-3))))&gt;0.00001) stop("error in both trucation")
plot(function(x) test3(x, mu=0, sigma=1, nu=1),-3,3)
integrate(function(x) test3(x, mu=2, sigma=1, nu=1),-3,3)
#----------------------------------------------------------------------------------------
# discrete distribution
# left 
# Poisson truncated at zero means zero is excluded
test4&lt;-trun.d(par=c(0), family="PO", type="left")
test4(1)
dPO(1)/(1-pPO(0))
if(abs(test4(1)-dPO(1)/(1-pPO(0)))&gt;0.00001) stop("error in left trucation")
test4(1, log=TRUE)
log(dPO(1)/(1-pPO(0)))
if(abs(test4(1, log=TRUE)-log(dPO(1)/(1-pPO(0))))&gt;0.00001) stop("error in left trucation")
 sum(test4(y=1:20, mu=2)) # 
 sum(test4(y=1:200, mu=80)) #
plot(function(y) test4(y, mu=20), from=1, to=51, n=50+1, type="h") # pdf 
# right truncated at 10 means 10 is included
test5&lt;-trun.d(par=c(10), family="NBI", type="right")
test5(2)
dNBI(2)/(pNBI(10))
if(abs(test5(1)-dNBI(1)/(pNBI(10)))&gt;0.00001) stop("error in right trucation")
test5(1, log=TRUE)
log(dNBI(1)/(pNBI(10)))
if(abs(test5(1, log=TRUE)-log(dNBI(1)/(pNBI(10))))&gt;0.00001) stop("error in right trucation")
sum(test5(y=0:10, mu=2,   sigma=2)) # 
sum(test5(y=0:10, mu=300, sigma=5)) # can have mu &gt; parameter
plot(function(y) test5(y, mu=20, sigma=3), from=0, to=10, n=10+1, type="h") # pdf
plot(function(y) test5(y, mu=300, sigma=5), from=0, to=10, n=10+1, type="h") # pdf
#----------------------------------------------------------------------------------------
# both
test6&lt;-trun.d(par=c(0,10), family="NBI", type="both")
test6(2)
dNBI(2)/(pNBI(10)-pNBI(0))
if(abs(test6(2)-dNBI(2)/(pNBI(10)-pNBI(0)))&gt;0.00001) stop("error in right trucation")
test6(1, log=TRUE)
log(dNBI(1)/(pNBI(10)-pNBI(0)))
if(abs(test6(1, log=TRUE)-log(dNBI(1)/(pNBI(10)-pNBI(0))))&gt;0.00001) 
           stop("error in right trucation")
sum(test6(y=1:10, mu=2,   sigma=2)) # 
 sum(test6(y=1:10, mu=100, sigma=5)) # can have mu &gt; parameter
plot(function(y) test6(y, mu=20, sigma=3), from=1, to=10, n=10, type="h") # pdf
plot(function(y) test6(y, mu=300, sigma=.4), from=1, to=10, n=10, type="h") # pdf
#----------------------------------------------------------------------------------------
</pre>

<script Language="JScript">
function findlink(pkg, fn) {
var Y, link;
Y = location.href.lastIndexOf("\\") + 1;
link = location.href.substring(0, Y);
link = link + "../../" + pkg + "/chtml/" + pkg + ".chm::/" + fn;
location.href = link;
}
</script>


<hr><div align="center">[Package <em>gamlss.tr</em> version 1.8-1 <a href="00Index.html">Index]</a></div>

</body></html>
